package org.easytouseit.websocket.receiver;

import org.easytouseit.websocket.handler.SocketHandler;
import org.easytouseit.websocket.model.WsResponse;
import org.easytouseit.websocket.utils.JacksonUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.socket.TextMessage;

/**
 * @author guojm
 * @version V1.0
 * @date 2019-01-09 下午 16:10
 */
@Service
public class RedisReceiver {
    @Autowired
    private SocketHandler socketHandler;
    public void receiveMessage(String message) {
        System.out.println("消息来了："+message);
        //这里是收到通道的消息之后执行的方法
        WsResponse<String> response = new WsResponse<>();
        response.setResult(message);
        socketHandler.sendMessagesToUsers(new TextMessage(JacksonUtil.bean2Json(response)));
    }
}
